import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Test6 {
	public static void main(String[] args) {
		String[] A = { "I Coder", "i am a coder", "Coder Coder", "Code",
				"i Coder Coder", "Coder Coder" };
		// [CODER CODER, CODER CODER, I CODER CODER, I AM A CODER]

		String[] findCoder = findCoder(A, A.length);
		System.out.println(Arrays.toString(findCoder));
	}

	public static String[] findCoder(String[] A, int n) {
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < A.length; i++) {
			String str = A[i].toLowerCase();
			if (str.contains("coder")) {
				list.add(str);
			}
		}
		String strs[] = new String[list.size()];
		list.toArray(strs);
		// 冒泡排序
		for (int i = 0; i < strs.length - 1; i++) {
			for (int j = 0; j < strs.length - i - 1; j++) {
				if (strs[j + 1] != null && strs[j + 1].length() > 0) {
					String s1 = strs[j].toLowerCase();
					String s2 = strs[j + 1].toLowerCase();
					String replaceAll1 = s1.replaceAll("coder", "");
					String replaceAll2 = s2.replaceAll("coder", "");
					int count1 = (s1.length() - replaceAll1.length()) / 5;
					int count2 = (s2.length() - replaceAll2.length()) / 5;
					if (count1 < count2) {
						String str = strs[j];
						strs[j] = strs[j + 1];
						strs[j + 1] = str;
					}
				}
			}
		}

		return strs;

	}
}
